package com.baymax.test.scene.internal

import android.util.Log
import android.view.View

/**
 * @title: 标题
 * @project: TestScene
 * @package: com.baymax.test.scene.internal
 * @class: TransLationViewWrapper
 * @description:
 *
 *
 * 类描述
 *
 *
 * @version: 1.0
 * @createDate: 2023/2/3 13:13
 * @Copyright (C) 2023 YSTEN
 * @author: xuyujian
 */
class TranslationViewWrapper(
    v: View,
    style: Style,
    private val styles: List<Style>,
    private val endValue: Int
) :
    Abstract21ViewWrapper(v, style) {
    fun log(m: String) {
        Log.d("TranslationViewWrapper", m)
    }

    private val sortLeft = styles.sortedBy { it.left }
    private val rightEnd = style.right > 1480

    init {
        require(styles.isNotEmpty())
    }

    override fun onChangeWidth(o: Int, n: Int) {
        log("onChangeWidth $o ->$n")
        style.renderWidth = n
        render(styles, o, n)
    }

    private fun render(styles: List<Style>, o: Int, n: Int) {
        if (rightEnd) {
            //left
            sortLeft.forEach {
                if (it.renderLeft > style.renderRight){
                    //左移不修改右侧的
                } else {
                    it.renderLeft -= n - o
                }
            }
        } else {
            sortLeft.reduce { left, right ->
                right.renderLeft = left.renderRight + (right.left - left.right)
                right
            }
        }
        log("render end $styles")
    }
}